import { IOrderProduct } from '../inteface/order'
import { get, post } from '../utils/request'

/**
 * 提交订单
 * @param data date: string; addressId: string; productId: string[]
 * @returns
 *
 *
 * productId	String	yes	产品id
 * detailType	SnapShort/Package	false	快照/套餐枚举
 * detailId	Long	false	快照或套餐id
 * addressId	Long	yes	地址id
 * 请求示例
 */
export const orderSubmit = async (data: IOrderProduct) => {
  try {
    const res = await post<{ result: { orderNo: string } }>('/api/order/submit', data)
    return res
  } catch (error) {
    console.error('新增预约失败:', error)
    return undefined
  }
}

export interface AppointmentDetail {
  detail: {
    orderNo: string
    address: {
      id: number
      uid: string
      phone: string
      address: string
      isDefault: boolean
      name: string
    }
    beginAt: number
    endAt: number
    totalPrice: number
    fee: number
    status: string
    quotationInfo: string
    contractInfo: string
    workInfo: string
    checkInfo: string
    products: {
      images: string[]
      name: string
      description: string
      duration: string
      spaceUnit: string
      spaceSize: number
      buildSize: number
    }[]
  }
}

// /appointment/detail
export const getAppointmentDetail = async (id: string) => {
  try {
    const res = await get<AppointmentDetail>(`/api/order/detail`, { data: { orderNo: id } })
    return res
  } catch (error) {
    console.error('获取预约详情失败:', error)
    return undefined
  }
}
